package eMdP.inputHandler.accions.EMdPHandler;



import com.jme.input.action.InputActionEvent;
import com.jme.input.action.KeyInputAction;
import com.jme.math.Vector3f;
import com.jme.util.Timer;

import eMdP.classesBasiques.Personatge;
import eMdP.inputHandler.EMdPHandler;

/**
 * 
 * <code>ThirdPersonLeftAction</code>
 * 
 * @author Joshua Slack
 * @version $Revision: 4131 $
 */
public class EsquerraEMdPAction extends KeyInputAction {

    private Vector3f rot;

    private EMdPHandler handler;
    
    private Personatge personatge;

    /**
     * Constructor creates a new <code>ThirdPersonLeftAction</code> object.
     * During construction, the character to direct and the speed at which to
     * move the character is set.
     * 
     * @param character
     *            the character that will be affected by this action.
     * @param speed
     *            the speed at which the camera can move.
     */
    public EsquerraEMdPAction(EMdPHandler handler, float speed) {
        this.handler = handler;
        this.speed = speed;
        rot = new Vector3f();
        
        personatge = ((Personatge)handler.getJugador());
    }

    /**
     * <code>performAction</code> moves the node along it's positive direction
     * vector at a speed of movement speed * time. Where time is the time
     * between frames and 1 corresponds to 1 second.
     * 
     * @see com.jme.input.action.InputActionInterface#performAction(InputActionEvent)
     */
    public void performAction(InputActionEvent event) {
    	if(!((Personatge)handler.getJugador()).estaBloquejat(Timer.getTimer().getTimeInSeconds())){
		    handler.setTurning(true);
		    Vector3f loc = handler.getTarget().getLocalTranslation();
		    if (handler.isCameraAlignedMovement()) {
		        rot.set(handler.getCamera().getLeft());
		        rot.y = 0;
		    } else {
		        handler.getTarget().getLocalRotation().getRotationColumn(2, rot);
		        rot.negateLocal();
		    }
		    rot.normalizeLocal();
		    loc.addLocal(rot.multLocal((speed * event.getTime())));
		    if(!personatge.estaCaminant())
	        {
	        	personatge.posaCaminant();
	        }
    	}
    }
}
